
R3F_FNCT_Patrol = {
	private ["_group","_radius","_building","_center","_wp","_near_roads"];
	_group = _this select 0;
	if (typeName _group != "GROUP") exitWith {};
	_radius = _this select 1;
	if (typeName _radius != "SCALAR") exitWith {};
	_building = if (count _this > 2) then {_this select 2;} else {false;};
	if (typeName _building != "BOOL") exitWith {};
	_center = getPos (leader _group);
	_wp = _group addWaypoint [_center,_radius];
	_wp setWaypointCompletionRadius 30;
	if (side _group == civilian) then {_wp setWaypointBehaviour "CARELESS";} else {_wp setWaypointBehaviour "SAFE";};
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "LIMITED";
	if ({vehicle _x != _x} count units _group > 0) then {
		_wp setWaypointFormation "FILE";
		_wp setWaypointTimeout [0,0,0];
	} else {
		_wp setWaypointFormation "COLUMN";
		_wp setWaypointTimeout [0,15,30];
	};
	_near_roads = _center nearRoads _radius;
	_group setVariable ["WP_BUILDING",_building,true];
	_group setVariable ["WP_POS",_center,true];
	_group setVariable ["WP_RADIUS",_radius,true];
	_group setVariable ["WP_ROADS",_near_roads,true];
	_wp setWaypointStatements ["true","
		[this] call R3F_FNCT_WPFindPos;
		[this] spawn {
			private [""_wp"",""_group"",""_driver"",""_vehicle"",""_damage""];
			_wp = _this select 0;
			_group = group _wp;
			{	_vehicle = vehicle _x;
				if (_vehicle != _x) then {
					_damage = damage _vehicle;
					sleep 15;
					if (alive _vehicle) then {
						_vehicle setDamage _damage;
						if (fuel _vehicle < 0.25) then {
							_vehicle setFuel 0.25;
						};
					};
				};
			} forEach units _group;
		};
	"];
};
R3F_FNCT_WPFindPos = {
	private ["_wp","_group","_building","_center","_radius","_near_roads","_nb_roads","_safepos","_vehicle","_units","_unit","_pos"];
	_wp = _this select 0;
	_group = group _wp;
	_building = _group getVariable "WP_BUILDING";
	_center = _group getVariable "WP_POS";
	_radius = _group getVariable "WP_RADIUS";
	_near_roads = _group getVariable "WP_ROADS";
	_nb_roads = count _near_roads;
	_safepos = false;
	_vehicle = false;
	_units = units _group;
	_unit = _units select 0;
	{	if (vehicle _x != _x) then {_vehicle = true;_unit = driver (vehicle _x);};
	} forEach _units;
	if ((_vehicle) && (_nb_roads > 5) && (_radius > 200) && ((getPosATL _unit) select 2 < 2)) then {
		_pos = getpos (_near_roads select (floor (random _nb_roads)));
		if (isOnRoad _pos) then {_safepos = true;};
	} else {
		_pos = [_center,_radius] call R3F_FNCT_SafePos;
		if  (count _pos != 0) then {_safepos = true;};
		if (_building) then {
			if ((!_vehicle) && (random 1 > 0.5) && _safepos) then {
				private ["_array","_count"];
				_array = [_pos,50] call R3F_FNCT_BuildingPos;
				_count = count _array;
				if (_count > 0) then {_pos = _array select (floor (random _count));};
			};
		};
	};
	if (!(isNull _group) && _safepos) exitWith {
		[_group, 1] setWaypointPosition [_pos,0];
		true;
	};
	diag_log format ["*** DEBUG PATROL EXIT (sans nouveau wp) : %1 - %2",_group,_center];
};
